package com.tedu.openmedical.medicalsystem.UserRole.controller;

import com.tedu.openmedical.medicalsystem.UserRole.pojo.dto.RoleUserSaveParam;
import com.tedu.openmedical.medicalsystem.UserRole.service.UserRoleService;
import com.tedu.openmedical.base.response.JsonResult;
import com.tedu.openmedical.medicalsystem.UserRole.pojo.vo.UserRoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/userRole/")
@Slf4j
@Api(tags = "用户角色管理")
public class UserRoleController {

    @Autowired
    private UserRoleService userRoleService;


    @GetMapping("selectUserRole")
    @ApiOperation(value = "查询用户角色", notes = "查询用户角色接口")
    public JsonResult selectUserRole(@RequestParam("roleName") String roleName){
        log.debug("roleName: {}", roleName);
        List<UserRoleVO> userRoleVOList = userRoleService.selectUserRole(roleName);
        return JsonResult.ok(userRoleVOList);
    }

    @PostMapping("deleteUserRole")
    @ApiOperation(value = "删除用户角色", notes = "删除用户角色接口")
    @ApiImplicitParams(@ApiImplicitParam(name = "roleId", value = "角色ID", required = true, dataType = "Long", paramType = "query"))
    public JsonResult deleteUserRole(Long roleId){
        log.debug("roleId: {}", roleId);
        userRoleService.deleteUserRole(roleId);
        return JsonResult.ok();
    }

    @PostMapping("addRoleUser")
    @ApiOperation(value = "新增用户角色", notes = "新增用户角色接口")
    public JsonResult addRoleUser(@RequestBody RoleUserSaveParam roleUserSaveParam){
        log.debug("roleUserSaveParam: {}", roleUserSaveParam);
        userRoleService.addRoleUser(roleUserSaveParam);
        return JsonResult.ok();
    }
}
